package com.erp.erp_ui.Drawback.Controller;

import com.erp.erp_entitys.Drawback.req.AddDrawbackReq;
import com.erp.erp_entitys.Drawback.req.QueryDrawbackReq;
import com.erp.erp_entitys.Drawback.vo.QueryDrawbackDetailVO;
import com.erp.erp_entitys.User.UserEntity;
import com.erp.erp_servers.Drawback.DrawbackService;
import com.erp.erp_ui.Drawback.Service.DrawbackAllService;
import com.erp.erp_ui.base.Base;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author zjk
 * @version 1.0
 * @description
 * @date 2021/1/12/012 23:41
 */
@Controller
@RequestMapping(value = "drawback")
public class DrawbackController extends Base {
    /**
     * 日志
     */
    private static final Logger log= LoggerFactory.getLogger(DrawbackController.class);
    private final DrawbackService drawbackService;
    private final DrawbackAllService drawbackAllService;
    public DrawbackController(DrawbackService drawbackService, DrawbackAllService drawbackAllService) {
        this.drawbackService = drawbackService;
        this.drawbackAllService = drawbackAllService;
    }
    /**
     * 获取当前登录用户
     * @return
     */
    @RequestMapping("getThisUser")
    @ResponseBody
    public R getThisUser(){
        try {
            log.info("获取当前登录用户");
            UserEntity userEntity= (UserEntity) this.getBean("user");
            return R.build(userEntity);
        } catch (Exception e) {
            log.error("费用->费用付款->获取当前登录用户功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 按条件查询退税信息
     * @param req 入参
     * @return
     */
    @RequestMapping("findDrawbackListByPage")
    @ResponseBody
    public R findDrawback(QueryDrawbackReq req){
        try {
            log.info("按条件查询退税信息");
            PageInfo pageInfo=drawbackService.selectDrawbackByParam(req);

            return R.build(0,"",pageInfo.getTotal(),pageInfo.getList());
        } catch (Exception e) {
            log.error("费用->退税->按条件查询退税信息功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
    /**
     * 根据登记id获取需要退税的报关信息
     * @param drawbackId 入参
     * @return
     */
    @RequestMapping("findDrawbackDetail")
    @ResponseBody
    public R findDrawback(@RequestBody Integer drawbackId){
        try {
            log.info("根据登记id获取需要退税的报关信息");
            QueryDrawbackDetailVO drawbackDetailList=drawbackAllService.findDrawbackDetail(drawbackId);
            return R.build(drawbackDetailList);
        } catch (Exception e) {
            log.error("费用->退税->根据登记id获取需要退税的报关信息功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     *  添加退税信息
     * @param reqData 入参
     * @return
     */
    @PostMapping("addDrawback")
    @ResponseBody
    public R addDrawback(@RequestBody AddDrawbackReq reqData){
        try {
            log.info("根据登记id获取需要退税的报关信息");
            return R.build(drawbackAllService.add(reqData));
        } catch (Exception e) {
            log.error("费用->退税->根据登记id获取需要退税的报关信息功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 修改退税的状态
     * @param drawbackId
     * @param drawbackStatus
     * @return
     */
    @PostMapping("updateDrawbackStatus")
    @ResponseBody
    public R updateDrawbackStatus(Integer drawbackId,Integer drawbackStatus){
        try {
            log.info("根据登记id获取需要退税的报关信息");
            return R.build(drawbackService.updateDrawbackStatus(drawbackId,drawbackStatus));
        } catch (Exception e) {
            log.error("费用->退税->根据登记id获取需要退税的报关信息功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 修改颜色
     * @param drawbackId
     * @param color
     * @return
     */
    @PostMapping("updateMarkColor")
    @ResponseBody
    public R updateMarkColor(Integer drawbackId,String color){
        try {
            log.info("根据登记id获取需要退税的报关信息");
            return R.build(drawbackService.updateMarkColor(drawbackId,color));
        } catch (Exception e) {
            log.error("费用->退税->根据登记id获取需要退税的报关信息功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
}
